//获取链接的参数	
var curPath=window.document.location.href;
var pathName=window.document.location.pathname;

var pos=curPath.indexOf(pathName);
var localhostPath=curPath.substring(0,pos);
var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
domainName = localhostPath;
var	path = localhostPath + projectName;


//获拼接的参数
if(location.href.split('?')[1]){
    var ids = location.href.split('?')[1].split('-')[0];
    var source = location.href.split('?')[1].split('-')[1];
    var activityId = location.href.split('?')[1].split('-')[2];
    var province = location.href.split('?')[1].split('-')[3];
    var city = location.href.split('?')[1].split('-')[4].substr(0,6);
}
$("#tip1").hide();
//获取活动详情
function getActivity(codes){
    var codes= {
        filialeId:codes
    };
    codes=JSON.stringify(codes);
    $.ajax({
        type: "post",
        dataType: "json",
        contentType: "application/json",
        url: path+"/app/selectFilialeActivityByCode",
        data:codes,
        success: function (data) {
            if(data.code=='0'){
                $('#wait').css('display','none');
                var resultData = data.result;
                console.log(resultData);
                $('#option').attr("src",resultData.imgurl);
                $('.textTitle').html(resultData.name);  //名称
                $('.definiteTimer1').html(resultData.start_time);//开始时间
                $('.definiteTimer2').html(resultData.end_time);//结束时间
                $('.activityAddress').html(resultData.stage);  //地址
                $('#activityText').html(resultData.details);  //活动详情

            }else if(data.code=='1'){
                alert("请求失败请联系服务人员！");
            }
        },
        error:function(data){
            console.log(data);
        }
    })
}
//验证手机号
function checkPhoneNumber2 (value){
    var phoneStr = /^1[3|4|5|7|8]\d{9}$/;
    if(phoneStr.test(value)){
        return true;
    }else{
        return false;
    }
};

//验证固定电话
function checkTellNumber1(value){
    var tellStr = /^(0[0-9]{2,3}\-)?([2-9][0-9]{6,9})+(\-[0-9]{1,4})?$/;
    if(tellStr.test(value)){
        return true;
    }else{
        return false;
    }
};
function checkPhoneNumberAll(){
    var strs =$('#phone').val();
    if(checkTellNumber1(strs)||checkPhoneNumber2(strs)){

    }else{
        $('#tipResult1').html('电话的格式不正确！请重试！');
        resultSure("1");
        $('#phone').val("");
    }
};

//提交数据
function submitData(){
    if(!$('#name').val()){
        $('#tipResult1').html('请填写姓名后再提交！');
        resultSure("1");
        $('#name').val("");
        return;
    }
    if(!$('#phone').val()){
        $('#tipResult1').html('请填写手机号后再提交！');
        resultSure("1");
        $('#phone').val("");
        return;
    }
    var resData = {
        phone:$('#phone').val(),
        filialeId:ids,
        source:source,
        activityId:activityId,
        province:province,
        city:city,
        name:$('#name').val()
    };
    resData = JSON.stringify(resData);
    $.ajax({
        type: "post",
        dataType: "json",
        contentType: "application/json",
        url: path+"/app/touTiaoRegister",
        data:resData,
        success: function (data) {
            if(data.code=='0'){ //成功
                $('#tipResult1').html("提交成功！\n 我们会尽快跟您联系！");
            }if(data.code=='1'){ //失败
                $('#tipResult1').html("提交失败！请联系我们！");
            }if(data.code=='2'){ //已经报名
                $('#tipResult1').html("该手机号已注册过圣象省心宝典，\n 可直接进入小程序报名活动");
            }
            resultSure("1");
            $('#name').val("");
            $('#phone').val("");

        },
        error:function(data){
            console.log(data);
        }
    })
}
function resultSure(id){
    if(id =='0'){  //隐藏
        $("#tip1").hide();
    }else if(id =='1'){  //显示
        $("#tip1").show();
    }

}
getActivity(activityId);
